home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_04
/
1004017a
< prev
next >
Wrap
Text File
|
1992-03-03
|
507b
|
25 lines
#include <stdlib.h>
#include <string.h>
typedef enum {FLOAT, INTEGER} Code;
typedef struct {
char *s;
Code code;
} Entry;
Entry symtab[] = {
{"float", FLOAT},
{"integer", INTEGER}}
static int cmp(const void *ck, const void *ce)
{ /* compare key to table element */
return (strcmp((const char *)ck, ((Entry *)ce)->s));
}
Entry *lookup(char *key)
{ /* lookup key in table */
return (bsearch(key, symtab,
sizeof symtab / sizeof symtab[0],
sizeof symtab[0], &cmp));
}